<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        img {
            vertical-align: top;
        }

        li {
            list-style: none;
        }

        a {
            text-decoration: none;
            color: inherit;
        }

        .adver-wrapper {
            width: 300px;
            /* height: 400px; */
            background-color: grey;
            position: fixed;
            right: 5px;
            bottom: 5px;
            /* display: none; */
        }

        .adver-header {
            line-height: 32px;
            position: relative;
        }

        .adver-header .adver-tips {
            font-size: 12px;
            text-indent: 13px;
        }

        .adver-header .adver-close {
            position: absolute;
            right: 5px;
            top: 0;
        }

        .adver-main img {
            width: 100%;
        }
    </style>
</head>

<body>
   
    <div id="app">
        <div class="adver-wrapper" v-if="isShow">
            <div class="adver-header">
                <div class="adver-tips">距离广告关闭还有{{countTime}}秒</div>
                <div class="adver-close" @click="closeHandler">x</div>
            </div>
            <div class="adver-main">
                <a href="">
                    <img src="../images/bzsc-dgbhz-300-250-7-5.gif" alt="">
                </a>
            </div>
           
        </div>
    </div>
</body>
<script>
   



    var vm = new Vue({
        el:"#app",
        data:{
            isShow:false,
            delayTime:5000,
            countTime:10,   //倒计时时间
            loop:true,
            timeoutTimer:null,
            intervalTimer:null,
        },
        methods: {
            showAdver:function(){
                clearTimeout(this.timeoutTimer);
                this.timeoutTimer = setTimeout(()=>{
                    this.isShow = true;
                    this.intervalTimer = setInterval(()=>{
                        console.log(111111);
                        this.countTime --;
                        if(this.countTime <=0){
                            clearInterval(this.intervalTimer);
                            this.countTime = 10;
                            this.isShow = false;
                            if(this.loop){
                                this.showAdver();
                            }
                        }
                    },1000);
                },this.delayTime);
            },
            closeHandler(){
                clearTimeout(this.timeoutTimer);
                clearInterval(this.intervalTimer);
                this.isShow = false;
                this.countTime = 10;
                if(this.loop){
                    this.showAdver();
                }
            }
        },
        mounted() {
           this.showAdver();
        },
    })

   

</script>

</html>